#include "actor.h"
#include "scene.h"
#include "../affiliate/affiliateBar.h"
#include "../raw/stats.h"

void Actor::update(float dt) {
    ObjectWorld::update(dt);
    updateHealthBar();
}

void Actor::move(float dt) {
    setPosition(position_ + velocity_ * dt); // 移动
    position_ = glm::clamp(position_, glm::vec2(0), game_.getCurrentScene()->getWorldSize()); // 限制在边界内
}

void Actor::takeDamage(float damage) {
    if (!stats_) {
        return;
    }
    stats_->takeDamage(damage);
}

bool Actor::isAlive() const {
    if (!stats_) {
        return false;
    }
    return stats_->getAlive();
}

void Actor::updateHealthBar() {
    if (!stats_ || !healthBar_) {
        return;
    }
    healthBar_->setPercentage(stats_->getHealth() / stats_->getMaxHealth());
}
